package com.fh;

import hk.ejs.util.Fun;
import hk.ejs.util.MyStringUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.Consts;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

public class APITest {
    /**
     * 
     * @param path
     * @param paraMap
     * @return
     * Author:sacada
     * Version:1.0
     * Time:2015年4月23日
     * Description:
     */
    public static String send(String path, Map<String,String> paraMap) {
        if(paraMap == null){
            paraMap = new HashMap<String, String>();
        }
        //String url = "http://115.29.205.160:8080/mall360/yun/es" + path;
//        String url = "http://test.cnhubei.com/zhdjpbd" + path;
//        String url = "http://dev.cnhubei.com/zhdjpbd" + path;
        String url = "http://127.0.0.1:8080/" + path;
        paraMap.put("ak","2");
        paraMap.put("tid", "ffffffff-b93c-a251-3713-1c7962cce3ff");//Y
        //paraMap.put("dc", "1,0,1,iaiS66qkt7AMpqmrT4iDsy62HjqbcVVLNYIf5WkqF3w=#5b14019e91871c376c26e9d3f87ac6f8");//600489481652670464  本地
        paraMap.put("dc", "5e8bce212d3f3e9e8f741f5a391fff3f");//600606209275596800
        //paraMap.put("dc", "");
        paraMap.put("v","1");
        paraMap.put("ts", String.valueOf((new Date()).getTime()));
        paraMap.put("p","a");
        //String sign = Fun.buildSignature(paraMap, "6yjhgfgnjkhebfh78");
        String sign = "";//Fun.buildSignature(paraMap, "zjMr3bxc");
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("sign", sign));
        for(Map.Entry<String, String> entry : paraMap.entrySet()){
            nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
        }
        
        HttpClient client = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url); 
        httppost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
        HttpResponse response = null;
        try {
            response = client.execute(httppost);
            return EntityUtils.toString(response.getEntity());
        }catch (ClientProtocolException e) {
            e.printStackTrace();
        }catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    public static void question() {
    	Map<String, String> paraMap = new HashMap<String, String>();
    	paraMap.put("infoid", "888331368201981952");
//    	paraMap.put("id", "871904116216172544");
    	paraMap.put("ckind", "5");
    	paraMap.put("content", "test32323");
    	paraMap.put("type", "0");
    	paraMap.put("scope", "2");
//    	paraMap.put("comid", "874081261147394048");
    	paraMap.put("word", "的");
//    	paraMap.put("cmd", "farther");
    	String ret = send("/app/m/user/test", paraMap);
//    	String ret = send("/plug/app/1/comm/list", paraMap);
//    	String ret = send("/app/1/work/list", paraMap);
        System.out.println(ret);
    }
    
    
    
    public static void main(String[] args) throws Exception{
    	question();
//    	System.out.println("aaa]".replace("[", "").replace("]", ""));
//    	long[] a = MyStringUtils.splitToLongArr("[876601664956796928,876607480808083456]", ",");
//    	System.out.println(a[0]);
    }	
}

